import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xindong/widgets/container/xindong_keep_alive_container.dart';
import 'package:xindong/widgets/gift/xindong_songli_controller.dart';
import 'package:xindong/widgets/gift/view/xindong_songli_yemian_view.dart';
import 'package:xindong/widgets/gift/view/xindong_songli_tab_bar.dart';

class XinDongSongLiBody extends StatefulWidget {
  const XinDongSongLiBody({super.key});

  @override
  State<XinDongSongLiBody> createState() => _XinDongSongLiBodyState();
}

class _XinDongSongLiBodyState extends State<XinDongSongLiBody> with TickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<XinDongSongLiController>(builder: (controller) {
      // 常规礼物
      if (controller.generalTabController == null ||
          controller.generalTabController?.length != controller.generalList.length) {
        controller.generalTabController = TabController(length: controller.generalList.length, vsync: this);
        // provider.generalTabControllerAdd(provider.generalTabController);
      }
      // 选项栏
      final List<Tab> titleTabs = controller.generalList.map((e) {
        return Tab(text: e.tabName);
      }).toList();
      // 选项视图
      final List<Widget> tabBarViews = controller.generalList.map((e) {
        return XinDongSongLiYeMianView(dataList: e.list);
      }).toList();
      return Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // 菜单栏
          XinDongSongLiTabBar(
            tabs: titleTabs,
            controller: controller.generalTabController,
            onTapBackpack: () {}, //controller.animateToBackpackYeMian,
          ),

          // 礼物栏(实时变化)
          SizedBox(
            height: 270,
            child: TabBarView(
              controller: controller.generalTabController,
              children: tabBarViews,
            ),
          ),
        ],
      );
    });
  }
}
